package com.xmg.design23.d22_mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: mazhongqing
 * @Date: 2021/3/25 15:07
 */
public class ConcreteMediator extends Mediator{
    private List<Colleague> colleagues = new ArrayList<>();
    @Override
    public void register(Colleague colleague) {
        if(!colleagues.contains(colleague)){
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague cl) {
        for (Colleague ob:colleagues){
            if(!ob.equals(cl)){
                ob.receive();
            }
        }
    }
}
